package org.dslintegration.validation;

import java.io.File;

import org.dslintegration.mRules.LeftAttribute;
import org.dslintegration.mRules.MRulesPackage;
import org.dslintegration.mRules.MergeRules;
import org.dslintegration.mRules.RightAttribute;
import org.dslintegration.mRules.Rule;
import org.dslintegration.mRules.RuleStatement;
import org.eclipse.xtext.validation.Check;

public class MRulesJavaValidator extends AbstractMRulesJavaValidator {

	@Check
	public void checkGreetingStartsWithCapital(Rule rule) {
		if (!Character.isUpperCase(rule.getRuleName().charAt(0))) {
			warning("Name should start with a capital", MRulesPackage.Literals.RULE__RULE_NAME);
		}
	}

	@Check
	public void checkLeft(LeftAttribute attribute) {
		if (Character.isUpperCase(attribute.getAttributeName().charAt(0))) {
			warning("Attribute should start with a lower case", MRulesPackage.Literals.LEFT_ATTRIBUTE__ATTRIBUTE_NAME);
		}
	}

	@Check
	public void checkRight(RightAttribute attribute) {
		if (Character.isUpperCase(attribute.getAttributeName().charAt(0))) {
			warning("Attribute should start with a lower case", MRulesPackage.Literals.RIGHT_ATTRIBUTE__ATTRIBUTE_NAME);
		}
	}

	@Check
	public void checkOutput(RuleStatement rule) {
		if (rule.getExpession().getLeft().size() > 1 || rule.getExpession().getLeft().size() > 1) {
			if (rule.getOutput() == null) {
				error("If expression is complex, it must contain output variable", MRulesPackage.Literals.RULE_STATEMENT__EXPESSION);
			}
		}
	}

	@Check
	public void check(MergeRules rules) {
		if (rules.getMetamodelPathLeft() != null) {
			if (!new File(rules.getMetamodelPathLeft()).exists() || !new File(rules.getMetamodelPathLeft()).isFile()) {
				error("File does not exist", MRulesPackage.Literals.MERGE_RULES__METAMODEL_PATH_LEFT);
			}

		}
		if (rules.getMetamodelPathRight() != null) {
			if (!new File(rules.getMetamodelPathRight()).exists() || !new File(rules.getMetamodelPathRight()).isFile()) {
				error("File does not exist", MRulesPackage.Literals.MERGE_RULES__METAMODEL_PATH_RIGHT);
			}
		}

	}
	
	

}
